package com.iwdm.renovation.ui.furniture_area;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.databinding.FragmentFurnitureareaListBinding;

public class FurnitureareaFragment extends Fragment {

    private static final String ARG_COLUMN_COUNT = "column-count";

    FragmentFurnitureareaListBinding binding;
    private int mColumnCount = 1;

    public FurnitureareaFragment() {
    }

    public static FurnitureareaFragment newInstance(int columnCount) {
        FurnitureareaFragment fragment = new FurnitureareaFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_COLUMN_COUNT, columnCount);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
        }
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,  ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentFurnitureareaListBinding.inflate(getLayoutInflater(), container, false);
        // Set the adapter
        Context context = binding.getRoot().getContext();
        RecyclerView recyclerView = binding.list;
        if (mColumnCount <= 1) {
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
        } else {
            recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
        }
        recyclerView.setAdapter(new MyFurnitureareaRecyclerViewAdapter());
        return binding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}
